import {initUrl} from "./config.js"

export default function(url,data={},method="get"){
  return new Promise((resolve,reject)=>{
    wx.request({
      url: initUrl + url,
      success: (res) => {
        console.log("success", res)
        if(url==="/login/cellphone" && res.data.code === 200){
          wx.setStorage({
            key:"cookie",
            data:res.cookies.join(";")
          })
        }
        return resolve(res.data)
      },
      fail: (res) => {
        console.log("error", res)
        return reject(res.errMsg)
      },
      data,
      method,
      header:{
        cookie:wx.getStorageSync("cookie")
      }
    })
  })
}